//
//  ConstellationViewController.swift
//  BirthdayManager
//
//  Created by Apple on 2020/12/16.
//  Copyright © 2020 Charles. All rights reserved.
//

import UIKit

class ConstellationViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate{
    
    @IBOutlet weak var constellationName: UILabel!
    //@IBOutlet weak var dateRange: UILabel!
    //@IBOutlet weak var constellationType: UILabel!
    
    @IBOutlet weak var avatar: UIImageView!
    
    @IBOutlet weak var constellationDescription: UITextView!
    
    @IBAction func tap(_ sender: Any) {
        let imagePicker = UIImagePickerController()
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.photoLibrary){
            imagePicker.delegate=self
            imagePicker.sourceType = .photoLibrary
            present(imagePicker,animated: true,completion: nil)
        }
    }
    //拍照函数
    @IBAction func CameraAction(_ sender: Any) {
        let imagePicker = UIImagePickerController()
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.photoLibrary){
            imagePicker.delegate=self
            imagePicker.sourceType = .photoLibrary
            present(imagePicker,animated: true,completion: nil)
        }
    }
    
    //重写函数
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        let selectedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
        self.avatar.image=selectedImage
        dismiss(animated: true, completion: nil)
    }
    
    //获取上一个页面传来的数据
    var constellationMessage: constellation?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if let constellation=constellationMessage{
            constellationName.text=constellation.constellationName
            //dateRange.text=constellation.dateRange
            //constellationType.text=constellation.constellationType
            constellationDescription.text=constellation.constellationDescription
            avatar.image=constellation.poster
        }
            // Do any additional setup after loading the view.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */
    
    /*
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier=="save"{
            constellationMessage=constellation(constellationName: constellationName.text!, dateRange:dateRange.text!, constellationType: constellationType.text!, constellationDescription: constellationDescription.text!, avatar: avatar.image)
        }
        
    }
 */

}
